//
//  WNFrameManager.swift
//  WalkNovel
//
//  Created by Kevin on 2023/7/4.
//

import UIKit

let WNWindow: UIWindow? = UIApplication.shared.connectedScenes.filter { $0.activationState == .foregroundActive }.compactMap { $0 as? UIWindowScene }.first?.windows.filter { $0.isKeyWindow }.first

let WNSBManager: UIStatusBarManager? = UIApplication.shared.windows.filter {$0.isKeyWindow}.first?.windowScene?.statusBarManager

struct Screen {
    static let screen = (UIApplication.shared.connectedScenes.first as? UIWindowScene)?.screen
    static let bounds = Screen.screen?.bounds ?? .zero
    static let width  = Screen.screen?.bounds.width ?? 0.0
    static let height = Screen.screen?.bounds.height ?? 0.0
    static let scale = Screen.screen?.scale ?? 1
}

let ScreenW = Screen.width

let ScreenH = Screen.height

let supportFaceID = (WNSBManager?.statusBarFrame.height ?? 20) > 20

// 判断越狱
let cydia = UIApplication.shared.canOpenURL(URL(string: "cydia://")!)

let applications = FileManager.default.fileExists(atPath: "User/Applications/")

// 状态栏 高度
let StatusBarHeight  : CGFloat = getStatusBarHeight()
// 顶部安全距离
let NavMargin        : CGFloat = (getStatusBarHeight()-20)
// navi 总高度
let NaviTotalHeight  : CGFloat = (getStatusBarHeight()+44)
// 底部安全距离
let TabBarMargin     : CGFloat = getSafeTabBarTotalHeight()
// tabbar 总高度
let TabBarTotalHeight: CGFloat = (getSafeTabBarTotalHeight()+49)

// MARK: - 比例尺
extension UIResponder {
    public func scaleWidth(_ w: CGFloat) -> CGFloat {
        return w * ScreenW / 375.0
    }
    
    public func scaleHeight(_ h: CGFloat) -> CGFloat {
        // x 适配
        if supportFaceID {
            return h / 667.0 * 667.0
        }
        return h / 667.0 * ScreenH
    }
}
